﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;

public class DataInitController : MonoBehaviour
{
    public static DataInitController _instance;



    private void Awake()
    {
        _instance = this;

        ChangeLanguage("config/CH/gameuidata");
    }
    private void ChangeLanguage(string path)
    {
        TextAsset ta = Resources.Load<TextAsset>(path);
        if(ta == null)
        {
            Debug.LogWarning("没有语言文件");
            return;
        }
        JsonData data = JsonMapper.ToObject(ta.text);
        IDictionary dict = data as IDictionary;

        foreach(string jd in dict.Keys)
        {
            switch (jd)
            {
                case "loadtext":
                    for (int i = 0; i < data[jd].Count; i++)
                    {
                        LanguageData._instance.loadmsg.Add(data[jd][i].ToString());
                    }
                    break;
                case "topscore":
                    LanguageData._instance.topscore = dict[jd].ToString();
                    break;
                case "toplv":
                    LanguageData._instance.toplv = dict[jd].ToString();
                    break;
                case "jindu":
                    LanguageData._instance.jindu = dict[jd].ToString();
                    break;
                case "jiandan":
                    LanguageData._instance.jiandan = dict[jd].ToString();
                    break;
                case "zhongdeng":
                    LanguageData._instance.zhongdeng = dict[jd].ToString();
                    break;
                case "kunnan":
                    LanguageData._instance.kunnan = dict[jd].ToString();
                    break;
                case "currentscore":
                    LanguageData._instance.currentscore = dict[jd].ToString();
                    break;
                case "currentlv":
                    LanguageData._instance.currentlv = dict[jd].ToString();
                    break;
                case "item1Text":
                    LanguageData._instance.item1 = dict[jd].ToString();
                    break;
                case "item3text":
                    LanguageData._instance.item2 = dict[jd].ToString();
                    break;
                case "item2text":
                    LanguageData._instance.item3 = dict[jd].ToString();
                    break;
                case "xulie":
                    for (int i = 0; i < data[jd].Count; i++)
                    {
                        LanguageData._instance.xulie.Add(data[jd][i].ToString());
                    }
                    break;
                default:
                    if (!LanguageData._instance.languagedic.ContainsKey(jd))
                        LanguageData._instance.languagedic.Add(jd, dict[jd].ToString());
                    break;
            }
           
        }
    }
}


class LanguageData
{
    private static LanguageData instance;
    public static LanguageData _instance
    {
        get
        {
            if (instance == null)
                instance = new LanguageData();
            return instance;
        }
    }

    public Dictionary<string, string> languagedic = new Dictionary<string, string>();
    public List<string> loadmsg = new List<string>();


    public string topscore;
    public string toplv;
    public string jindu;
    public string jiandan;
    public string zhongdeng;
    public string kunnan;
    public string currentscore;
    public string currentlv;
    public string item1;
    public string item2;
    public string item3;
    public List<string> xulie = new List<string>();
}
